<template>
	<view class="tabbar-container" :style="padding">
		<block>
			<view class="tabbar-item" v-for="(item, index) in tabbarList"
				:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem == item.id ? item.selectedIconPath : item.iconPath"></image>
				</view>
				<view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
					<text>{{ item.text }}</text>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				padding: 0,
				currentItem: 0,
				tabbarList: [{
						"id": 0,
						"pagePath": "/pages/index/index",
						"iconPath": "/static/icon/icon_tab_0.png",
						"selectedIconPath": "/static/icon/icon_tab_s0.png",
						"text": "首页",
						"centerItem": false
					},
					{
						"id": 1,
						"pagePath": "/pages/company/index",
						"iconPath": "/static/icon/icon_tab_1.png",
						"selectedIconPath": "/static/icon/icon_tab_s1.png",
						"text": "公司介绍",
						"centerItem": false
					},
					{
						"id": 2,
						"pagePath": "/pages/shop/index",
						"iconPath": "/static/icon/icon_tab_2.png",
						"selectedIconPath": "/static/icon/icon_tab_2.png",
						"text": '商城',
						"centerItem": true
					},
					{
						"id": 3,
						"pagePath": "/pages/task/index",
						"iconPath": "/static/icon/icon_tab_3.png",
						"selectedIconPath": "/static/icon/icon_tab_s3.png",
						"text": "橱窗任务",
						"centerItem": false
					},
					{
						"id": 4,
						"pagePath": "/pages/user/index",
						"iconPath": "/static/icon/icon_tab_4.png",
						"selectedIconPath": "/static/icon/icon_tab_s4.png",
						"text": "我的",
						"centerItem": false
					}
				]
			};
		},
		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();
			let safeBottom = this.getSafeAreaInsets().bottom
			if (safeBottom > 0) {
				let h = (safeBottom - 10) * 2
				this.padding = 'padding-bottom:' + h + 'rpx;height: ' + (110 + h) + 'rpx;'
			}
			console.log(this.padding)
		},
		methods: {
			changeItem(item) {
				let _this = this;
				//_this.currentItem = item.id;
				uni.switchTab({
					url: item.pagePath
				});
			},
			getSafeAreaInsets() {
				let safeAreaInsets = 0
				uni.getSystemInfo({
					success: function (res) {
						console.log(res)
						safeAreaInsets = res.safeAreaInsets
					}
				})
				return safeAreaInsets
			}
		}
	};
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 110rpx;
		box-shadow: 0 0 5px #999;
		display: flex;
		align-items: center;
		padding: 5rpx 0rpx 5rpx 0rpx;
		color: #999999;
		z-index: 99999;
		background-color: #ffffff;
	}

	.tabbar-container .tabbar-item {
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}

	.tabbar-container .item-active {
		color: #9F6F26;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 70rpx;
		height: 70rpx;
		padding: 10rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -40rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0 0 5px #999;
		background-color: #ffffff;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}
	
	.tabbar-container .center-item .item-top image {
		width: 48rpx;
		height: 48rpx;
		margin-top: 20rpx;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 22rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 0rpx;
	}
</style>